﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

namespace LeadMaster.Helpers
{
  public static class BespokeFunctions
  {

    public static string Proper(string inString)
    {
      string outString = string.Empty;
      char[] charArray = inString.ToCharArray();
      bool isSpace = true;
      foreach (char item in charArray)
      {
        if (isSpace)
        {
          outString += Char.ToUpper(item);
        }
        else
        {
          outString += Char.ToLower(item);
        }
        isSpace = item == ' ';
      }

      return outString;
    }

    public static bool ValidatePostcode(string postcode)
    {
      Regex regex = new Regex("^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKPS-UW]) {0,1}[0-9][ABD-HJLNP-UW-Z]{2})$");
      return regex.IsMatch(postcode.ToUpper().Trim());
    }

  }
}